<template>
	<view>
		<view v-for="item in news" :key="item.id" @click="navigator(item.id)">
			<view class="item">
				<image :src="item.img_url"/>
				<view class="right">
					<view class="title">{{item.title}}</view>
					<view class="content">
						<text>发表时间：{{item.add_time|formatDate}}</text><!-- 使用过滤器formatDate -->
						<text>浏览：{{item.click}}次</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default({
		props:{
			news:Array
		},
		// 过滤器
		filters:{
			formatDate(date){
				const nDate = new Date(date)
				return nDate.getFullYear()+"-"+nDate.getMonth().toString().padStart(2,0)+"-"+nDate.getDay().toString().padStart(2,0)
			}
		},
		methods:{
			navigator(newsId){
				this.$emit("itemClick",newsId)
			}
		}
	})
</script>

<style lang="scss">
		.item{
			display: flex;//一行显示
			padding: 10rpx 20rpx;
			border-bottom: 1px solid $shop-color;
			image{
				min-width: 200rpx;
				max-width: 200rpx;
				height: 150rpx;
			}
			.right{
				width: 550rpx;
				height: 200rpx;
				margin-left: 15rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					font-size: 30rpx;
				}
				.content{
					font-size: 24rpx;
					text:nth-child(2){
						margin-left: 30rpx;
					}
				}
			}
		}
</style>
